package com.ruoyi.eqmonitor.controller;

import cn.hutool.core.lang.Assert;
import com.ruoyi.eqmonitor.utils.TTSUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "TTS接口")
@RestController
@RequestMapping("/tts")
public class TTSController {

    /**
     * 文字转语音 暂时没有人用
     */
    @GetMapping("/textToSpeech")
    public ResponseEntity<byte[]> textToSpeech(@RequestParam("text") String text) {
        Assert.notBlank(text, "请输入要转换的文字");
        byte[] bytes = TTSUtil.textToSpeechByteArray(text);
        return ResponseEntity.ok()
                .header(HttpHeaders.CONTENT_TYPE, "audio/mpeg;charset=utf-8")
                .header(HttpHeaders.CONTENT_LENGTH, String.valueOf(bytes.length))
                .header(HttpHeaders.CACHE_CONTROL, "public,max-age=360000")
                .body(bytes);
    }

}
